package org.example.controller;

import lombok.extern.slf4j.Slf4j;
import org.example.anno.Log;
import org.example.pojo.Emp;
import org.example.pojo.LoginInfo;
import org.example.pojo.Result;
import org.example.service.imp.EmpServiceImp;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Slf4j
@RestController
@RequestMapping("/login")
public class LoginController {
    private final EmpServiceImp empServiceImp;
    public LoginController(EmpServiceImp empServiceImp)
    {
        this.empServiceImp = empServiceImp;
    } 
    /**
     * 登陆
     */
    @Log
    @PostMapping
    public Result login(@RequestBody Emp emp)
    {
        log.info("员工登陆:{}",emp);
        LoginInfo loginInfo = empServiceImp.login(emp);
        if(loginInfo != null){
            return Result.success(loginInfo);
        }
        return Result.error("用户名或密码错误");

    }
}
